import time

from selenium.webdriver.common.by import By
from common.Utils import ForumDriver

class HomePage:
    driver = ""
    url = ""
    def __init__(self):
        self.driver = ForumDriver.driver
        self.url = "http://127.0.0.1:9580/index.html"
        self.driver.get(self.url)

    def ForumLoginSucHomePage(self):
        #检查页面元素
        #检查论坛首页标识
        sign = self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > h1 > a > img").text
        print("论坛首页标识："+sign)
        #检查用户头像
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_avatar")
        #检查一下发布帖子按钮
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post")
        #检查论坛帖子列表页的用户头像
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col-auto > span")
        #检查帖子的标题
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong")
        #检查帖子的发布时间
        postptime = self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-muted.mt-2 > div > div.col > ul > li:nth-child(2)").text
        print("home帖子的发布时间："+postptime)
        #检查帖子的发布用户名称
        postpname = self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-muted.mt-2 > div > div.col > ul > li:nth-child(1)").text
        print("home发布帖子的用户："+postpname)
        ForumDriver.GetScreeShot()
        time.sleep(2)